{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 一、读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('weather_data.csv')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from pyecharts.charts import Line\n",
    "x_data = df.drop_duplicates(subset=['日期'])['日期'].tolist()\n",
    "beijing_data = df[df['城市']=='北京']['最高温'].tolist()\n",
    "shanghai_data = df[df['城市']=='上海']['最高温'].tolist()\n",
    "shenzhen_data = df[df['城市']=='深圳']['最高温'].tolist()\n",
    "for i, string in enumerate(beijing_data):\n",
    "    beijing_data[i] = string[:-1]\n",
    "for i, string in enumerate(shanghai_data):\n",
    "    shanghai_data[i] = string[:-1]\n",
    "for i, string in enumerate(shenzhen_data):\n",
    "    shenzhen_data[i] = string[:-1]"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 二、数据可视化"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "line = Line()\n",
    "line.add_xaxis(xaxis_data=x_data)\n",
    "line.add_yaxis(series_name='北京', y_axis=beijing_data)\n",
    "line.add_yaxis(series_name='上海', y_axis=shanghai_data)\n",
    "line.add_yaxis(series_name='深圳', y_axis=shenzhen_data)\n",
    "\n",
    "line.render_notebook()\n",
    "# line.render()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
